import 'dart:convert';

T? asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}

class AcMediaModel {
  AcMediaModel({
    required this.mediaType,
    required this.mediaPath,
    required this.thumbUrl,
    required this.middleThumbUrl,
    required this.mediaUrl,
  });

  factory AcMediaModel.fromJson(Map<String, dynamic> json) => AcMediaModel(
    mediaType: asT<String>(json['mediaType'])!,
    mediaPath: asT<String>(json['mediaPath'])!,
    thumbUrl: asT<String>(json['thumbUrl'])!,
    middleThumbUrl: asT<String>(json['middleThumbUrl'])!,
    mediaUrl: asT<String>(json['mediaUrl'])!,
  );

  String mediaType;
  String mediaPath;
  String thumbUrl;
  String middleThumbUrl;
  String mediaUrl;

  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
    'mediaType': mediaType,
    'mediaPath': mediaPath,
    'thumbUrl': thumbUrl,
    'middleThumbUrl': middleThumbUrl,
    'mediaUrl': mediaUrl,
  };
}
